/*
 * @Author: ShengXD <1519256482@qq.com>
 * @Date: 2024-11-06 11:31:20
 * @LastEditors: ShengXD <1519256482@qq.com>
 * @LastEditTime: 2024-11-06 15:14:45
 * @FilePath: /vben-quick-setup/apps/backend-mock/api/login.ts
 * @Description:
 */
import {
    clearRefreshTokenCookie,
    setRefreshTokenCookie,
  } from '~/utils/cookie-utils';
  import { generateAccessToken, generateRefreshToken } from '~/utils/jwt-utils';
  import { forbiddenResponse } from '~/utils/response';
  
  export default defineEventHandler(async (event) => {
    const { password, username } = await readBody(event);
    if (!password || !username) {
      setResponseStatus(event, 400);
      return useResponseError(
        'BadRequestException',
        'Username and password are required',
      );
    }
  
    // const findUser = MOCK_USERS.find(
    //   (item) => item.username === username && item.password === password,
    // );
  
    // if (!findUser) {
    //   clearRefreshTokenCookie(event);
    //   return forbiddenResponse(event, 'Username or password is incorrect.');
    // }
  
    // const accessToken = generateAccessToken(findUser);
    // const refreshToken = generateRefreshToken(findUser);
    // setRefreshTokenCookie(event, refreshToken);
  
    return useResponseSuccess({
      id: 0,
      password: '123456',
      realName: 'Vben',
      roles: ['super'],
      username: 'vben',
      accessToken:
        'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MCwicGFzc3dvcmQiOiIxMjM0NTYiLCJyZWFsTmFtZSI6IlZiZW4iLCJyb2xlcyI6WyJzdXBlciJdLCJ1c2VybmFtZSI6InZiZW4iLCJpYXQiOjE3MzA4NzY5MjQsImV4cCI6MTczMTQ4MTcyNH0.3O6z0wIkW93lsNGilfsSu-CGtQUuPXbBz5jFnBsQqqg',
    });
  });
  